package com.skzh.web.controller.equipment;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.skzh.common.core.domain.model.LoginUser;
import com.skzh.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.skzh.common.annotation.Log;
import io.swagger.annotations.ApiOperation;
import com.skzh.common.core.controller.BaseController;
import com.skzh.common.core.domain.AjaxResult;
import com.skzh.common.enums.BusinessType;
import com.skzh.equipment.domain.DockConfig;
import com.skzh.equipment.service.IDockConfigService;
import com.skzh.common.utils.poi.ExcelUtil;
import com.skzh.common.core.page.TableDataInfo;

/**
 * 机场设置Controller
 *
 * @author skzh
 * @date 2025-03-24
 */
@RestController
@RequestMapping("/equipment/config")
public class DockConfigController extends BaseController {
    @Autowired
    private IDockConfigService dockConfigService;

    /**
     * 查询机场设置列表
     */
    @ApiOperation(value = "查询机场设置列表")
    @PreAuthorize("@ss.hasPermi('equipment:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(DockConfig dockConfig) {
        startPage();
        List<DockConfig> list = dockConfigService.selectDockConfigList(dockConfig);
        return getDataTable(list);
    }

    /**
     * 导出机场设置列表
     */
    @ApiOperation(value = "导出机场设置列表")
    @PreAuthorize("@ss.hasPermi('equipment:config:export')")
    @Log(title = "机场设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DockConfig dockConfig) {
        List<DockConfig> list = dockConfigService.selectDockConfigList(dockConfig);
        ExcelUtil<DockConfig> util = new ExcelUtil<DockConfig>(DockConfig.class);
        util.exportExcel(response, list, "机场设置数据");
    }

    /**
     * 获取机场设置详细信息
     */
    @ApiOperation(value = "获取机场设置详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(dockConfigService.selectDockConfigById(id));
    }

    /**
     * 新增机场设置
     */
    @ApiOperation(value = "新增机场设置")
    @PreAuthorize("@ss.hasPermi('equipment:config:add')")
    @Log(title = "机场设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DockConfig dockConfig) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        dockConfig.setCreateBy(loginUser.getUsername());
        return toAjax(dockConfigService.insertDockConfig(dockConfig));
    }

    /**
     * 修改机场设置
     */
    @ApiOperation(value = "修改机场设置")
    @PreAuthorize("@ss.hasPermi('equipment:config:edit')")
    @Log(title = "机场设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DockConfig dockConfig) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        dockConfig.setUpdateBy(loginUser.getUsername());
        return toAjax(dockConfigService.updateDockConfig(dockConfig));
    }

    /**
     * 删除机场设置
     */
    @ApiOperation(value = "删除机场设置")
    @PreAuthorize("@ss.hasPermi('equipment:config:remove')")
    @Log(title = "机场设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dockConfigService.deleteDockConfigByIds(ids));
    }

    /**
     * 根据机场id获取机场设置详细信息
     */
    @ApiOperation(value = "根据机场id获取机场设置详细信息")
    @PreAuthorize("@ss.hasPermi('equipment:config:queryByDockId')")
    @GetMapping(value = "/query/{dockId}")
    public AjaxResult getInfoByDockId(@PathVariable("dockId") Long dockId) {
        return success(dockConfigService.selectDockConfigByDockId(dockId));
    }

    /**
     * 查询所有机场的id和名字
     */
    @ApiOperation(value = "查询所有机场的id和名字")
    @PreAuthorize("@ss.hasPermi('equipment:config:queryAllDockName')")
    @GetMapping("/allDockName")
    public List<Map<Object, Object>> getAllDockName() {
        return dockConfigService.selectAllDockName();
    }
}
